﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ZK.Common.IConfig;

namespace ZK.Common
{
    public class IConfig : ConfigurationSection
    {


        #region MHSNReader
        [ConfigurationProperty("MHSNReader", IsRequired = false)]
        public HaredWareCommonM MHSNReaderE
        {
            get
            {
                return (HaredWareCommonM)this["MHSNReader"];
            }
        }

        public static HaredWareCommonM GetSetMHSNReader
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).MHSNReaderE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.MHSNReaderE.BaudRate = value.BaudRate;
                iConfig.MHSNReaderE.DataBits = value.DataBits;
                iConfig.MHSNReaderE.PortName = value.PortName;
                iConfig.MHSNReaderE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region TrafficLightH
        [ConfigurationProperty("TrafficLightH", IsRequired = false)]
        public HaredWareCommonM TrafficLightHE
        {
            get
            {
                return (HaredWareCommonM)this["TrafficLightH"];
            }
        }

        public static HaredWareCommonM GetSetTrafficLightH
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).TrafficLightHE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.TrafficLightHE.BaudRate = value.BaudRate;
                iConfig.TrafficLightHE.DataBits = value.DataBits;
                iConfig.TrafficLightHE.PortName = value.PortName;
                iConfig.TrafficLightHE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region TrafficLightQ
        [ConfigurationProperty("TrafficLightQ", IsRequired = false)]
        public HaredWareCommonM TrafficLightQE
        {
            get
            {
                return (HaredWareCommonM)this["TrafficLightQ"];
            }
        }
        public static HaredWareCommonM GetSetTrafficLightQ
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).TrafficLightQE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (value.BaudRate > 0)
                    iConfig.TrafficLightQE.BaudRate = value.BaudRate;
                if (value.DataBits > 0)
                    iConfig.TrafficLightQE.DataBits = value.DataBits;
                if (!string.IsNullOrWhiteSpace(value.PortName.ToString()))
                    iConfig.TrafficLightQE.PortName = value.PortName;
                if (!string.IsNullOrWhiteSpace(value.Name.ToString()))
                    iConfig.TrafficLightQE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region Infrared
        [ConfigurationProperty("Infrared", IsRequired = false)]
        public HaredWareCommonM InfraredE
        {
            get
            {
                return (HaredWareCommonM)this["Infrared"];
            }
        }

        public static HaredWareCommonM GetSetInfrared
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).InfraredE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (value.BaudRate > 0)
                    iConfig.InfraredE.BaudRate = value.BaudRate;
                //if (value.DataBits > 0)
                //    iConfig.InfraredE.DataBits = value.DataBits;
                //if (!string.IsNullOrWhiteSpace(value.StopBits.ToString()))
                //    iConfig.InfraredE.StopBits = value.StopBits;
                //if (!string.IsNullOrWhiteSpace(value.Parity.ToString()))
                //    iConfig.InfraredE.Parity = value.Parity;
                if (!string.IsNullOrWhiteSpace(value.PortName))
                    iConfig.InfraredE.PortName = value.PortName;
                if (!string.IsNullOrWhiteSpace(value.Name))
                    iConfig.InfraredE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region DLZC
        [ConfigurationProperty("DLZC", IsRequired = false)]
        public HaredWareCommonM DLZCE
        {
            get
            {
                return (HaredWareCommonM)this["DLZC"];
            }
        }

        public static HaredWareCommonM GetSetDLZC
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).DLZCE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.DLZCE.BaudRate = value.BaudRate;
                iConfig.DLZCE.DataBits = value.DataBits;
                iConfig.DLZCE.PortName = value.PortName;
                iConfig.DLZCE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region WagonBalance
        [ConfigurationProperty("WagonBalance", IsRequired = false)]
        public HaredWareCommonM wagonBalanceE
        {
            get
            {
                return (HaredWareCommonM)this["WagonBalance"];
            }
        }

        public static HaredWareCommonM GetSetwagonBalance
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).wagonBalanceE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (value.BaudRate > 0)
                    iConfig.wagonBalanceE.BaudRate = value.BaudRate;
                if (value.DataBits > 0)
                    iConfig.wagonBalanceE.DataBits = value.DataBits;
                if (!string.IsNullOrWhiteSpace(value.StopBits.ToString()))
                    iConfig.wagonBalanceE.StopBits = value.StopBits;
                if (!string.IsNullOrWhiteSpace(value.Parity.ToString()))
                    iConfig.wagonBalanceE.Parity = value.Parity;
                if (!string.IsNullOrWhiteSpace(value.PortName))
                    iConfig.wagonBalanceE.PortName = value.PortName;
                if (!string.IsNullOrWhiteSpace(value.Name))
                    iConfig.wagonBalanceE.Name = value.Name;

                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesQ
        [ConfigurationProperty("CameraScalesQ", IsRequired = false)]
        public HaredWareCommonM CameraScalesQE
        {
            get
            {
                return (HaredWareCommonM)this["CameraScalesQ"];
            }
        }

        public static HaredWareCommonM GetSetCameraScalesQ
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesQE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (!string.IsNullOrWhiteSpace(value.Ip))
                    iConfig.CameraScalesQE.Ip = value.Ip;
                if (!string.IsNullOrWhiteSpace(value.Port))
                    iConfig.CameraScalesQE.Port = value.Port;
                if (!string.IsNullOrWhiteSpace(value.UserName))
                    iConfig.CameraScalesQE.UserName = value.UserName;
                if (!string.IsNullOrWhiteSpace(value.PassWord))
                    iConfig.CameraScalesQE.PassWord = value.PassWord;
                if (!string.IsNullOrWhiteSpace(value.Name))
                    iConfig.CameraScalesQE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LedQ
        [ConfigurationProperty("LedQ", IsRequired = false)]
        public HaredWareCommonM LedQE
        {
            get
            {
                return (HaredWareCommonM)this["LedQ"];
            }
        }

        public static HaredWareCommonM GetSetLedQ
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).LedQE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (!string.IsNullOrWhiteSpace(value.Ip))
                    iConfig.LedQE.Ip = value.Ip;
                if (value.Height > 0)
                    iConfig.LedQE.Height = value.Height;
                if (value.Width > 0)
                    iConfig.LedQE.Width = value.Width;
                if (!string.IsNullOrWhiteSpace(value.Name))
                    iConfig.LedQE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LedH
        [ConfigurationProperty("LedH", IsRequired = false)]
        public HaredWareCommonM LedHE
        {
            get
            {
                return (HaredWareCommonM)this["LedH"];
            }
        }

        public static HaredWareCommonM GetSetLedH
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).LedHE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.LedHE.Ip = value.Ip;
                iConfig.LedHE.Height = value.Height;
                iConfig.LedHE.Width = value.Width;
                iConfig.LedHE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LedDC
        [ConfigurationProperty("LedDC", IsRequired = false)]
        public HaredWareCommonM LedDCE
        {
            get
            {
                return (HaredWareCommonM)this["LedDC"];
            }
        }

        public static HaredWareCommonM GetSetLedDC
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).LedDCE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.LedDCE.Ip = value.Ip;
                iConfig.LedDCE.Height = value.Height;
                iConfig.LedDCE.Width = value.Width;
                iConfig.LedDCE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesH
        [ConfigurationProperty("CameraScalesH", IsRequired = false)]
        public HaredWareCommonM CameraScalesHE
        {
            get
            {
                return (HaredWareCommonM)this["CameraScalesH"];
            }
        }

        public static HaredWareCommonM GetSetCameraScalesH
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesHE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesHE.Ip = value.Ip;
                iConfig.CameraScalesHE.Port = value.Port;
                iConfig.CameraScalesHE.UserName = value.UserName;
                iConfig.CameraScalesHE.PassWord = value.PassWord;
                iConfig.CameraScalesHE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesG1
        [ConfigurationProperty("CameraScalesG1", IsRequired = false)]
        public HaredWareCommonM CameraScalesG1E
        {
            get
            {
                return (HaredWareCommonM)this["CameraScalesG1"];
            }
        }

        public static HaredWareCommonM GetSetCameraScalesG1
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesG1E;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesG1E.Ip = value.Ip;
                iConfig.CameraScalesG1E.Port = value.Port;
                iConfig.CameraScalesG1E.UserName = value.UserName;
                iConfig.CameraScalesG1E.PassWord = value.PassWord;
                iConfig.CameraScalesG1E.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesG2
        [ConfigurationProperty("CameraScalesG2", IsRequired = false)]
        public HaredWareCommonM CameraScalesG2E
        {
            get
            {
                return (HaredWareCommonM)this["CameraScalesG2"];
            }
        }

        public static HaredWareCommonM GetSetCameraScalesG2
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesG2E;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesG2E.Ip = value.Ip;
                iConfig.CameraScalesG2E.Port = value.Port;
                iConfig.CameraScalesG2E.UserName = value.UserName;
                iConfig.CameraScalesG2E.PassWord = value.PassWord;
                iConfig.CameraScalesG2E.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesG3
        [ConfigurationProperty("CameraScalesG3", IsRequired = false)]
        public HaredWareCommonM CameraScalesG3E
        {
            get
            {
                return (HaredWareCommonM)this["CameraScalesG3"];
            }
        }

        public static HaredWareCommonM GetSetCameraScalesG3
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesG3E;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesG3E.Ip = value.Ip;
                iConfig.CameraScalesG3E.Port = value.Port;
                iConfig.CameraScalesG3E.UserName = value.UserName;
                iConfig.CameraScalesG3E.PassWord = value.PassWord;
                iConfig.CameraScalesG3E.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CardReader
        [ConfigurationProperty("CardReader", IsRequired = false)]
        public HaredWareCommonM CardReaderE
        {
            get
            {
                return (HaredWareCommonM)this["CardReader"];
            }
        }

        public static HaredWareCommonM GetSetCardReader
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CardReaderE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (!string.IsNullOrWhiteSpace(value.Ip))
                    iConfig.CardReaderE.Ip = value.Ip;
                if (!string.IsNullOrWhiteSpace(value.Port))
                    iConfig.CardReaderE.Port = value.Port;
                if (!string.IsNullOrWhiteSpace(value.Name))
                    iConfig.CardReaderE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CardReaderDC
        [ConfigurationProperty("CardReaderDC", IsRequired = false)]
        public HaredWareCommonM CardReaderDCE
        {
            get
            {
                return (HaredWareCommonM)this["CardReaderDC"];
            }
        }

        public static HaredWareCommonM GetSetCardReaderDC
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CardReaderDCE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CardReaderDCE.Ip = value.Ip;
                iConfig.CardReaderDCE.Port = value.Port;
                iConfig.CardReaderDCE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CardReaderMW
        [ConfigurationProperty("CardReaderMW", IsRequired = false)]
        public HaredWareCommonM CardReaderMWE
        {
            get
            {
                return (HaredWareCommonM)this["CardReaderMW"];
            }
        }

        public static HaredWareCommonM GetSetCardReaderMW
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).CardReaderMWE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CardReaderMWE.Ip = value.Ip;
                iConfig.CardReaderMWE.Port = value.Port;
                iConfig.CardReaderMWE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region NRNetRelay
        [ConfigurationProperty("NRNetRelay", IsRequired = false)]
        public HaredWareCommonM NRNetRelayE
        {
            get
            {
                return (HaredWareCommonM)this["NRNetRelay"];
            }
        }

        public static HaredWareCommonM GetSetNRNetRelay
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).NRNetRelayE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (!string.IsNullOrWhiteSpace(value.Ip))
                    iConfig.NRNetRelayE.Ip = value.Ip;
                if (!string.IsNullOrWhiteSpace(value.Port))
                    iConfig.NRNetRelayE.Port = value.Port;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LengSheng
        [ConfigurationProperty("LengSheng", IsRequired = false)]
        public HaredWareCommonM LengShengE
        {
            get
            {
                return (HaredWareCommonM)this["LengSheng"];
            }
        }

        public static HaredWareCommonM GetSetLengSheng
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).LengShengE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if (!string.IsNullOrWhiteSpace(value.Ip))
                    iConfig.LengShengE.Ip = value.Ip;
                if (!string.IsNullOrWhiteSpace(value.Port))
                    iConfig.LengShengE.Port = value.Port;
                if (!string.IsNullOrWhiteSpace(value.Name))
                    iConfig.LengShengE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion


        #region UserInfo
        [ConfigurationProperty("UserInfo", IsRequired = false)]
        public UserInfo UserInfoE
        {
            get
            {
                return (UserInfo)this["UserInfo"];
            }
        }
        public class UserInfo : ConfigurationElement
        {
            /// <summary>
            /// 用户名
            /// </summary>
            [DisplayName("用户名")]
            [ConfigurationProperty("LoginAccount", IsRequired = false)]
            public string LoginAccount
            {
                get
                {
                    return this["LoginAccount"].ToString();
                }
                set
                {
                    this["LoginAccount"] = value;
                }
            }
            /// <summary>
            /// 密码
            /// </summary>
            [DisplayName("密码")]
            [ConfigurationProperty("PassWord", IsRequired = false)]
            public string PassWord
            {
                get
                {
                    return this["PassWord"].ToString();
                }
                set
                {
                    this["PassWord"] = value;
                }
            }
            /// <summary>
            /// token
            /// </summary>
            [DisplayName("token")]
            [ConfigurationProperty("Token", IsRequired = false)]
            public string Token
            {
                get
                {
                    return this["Token"].ToString();
                }
                set
                {
                    this["Token"] = value;
                }
            }
        }
        public static UserInfo GetSetuserInfo
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).UserInfoE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.UserInfoE.LoginAccount = value.LoginAccount;
                iConfig.UserInfoE.PassWord = value.PassWord;
                iConfig.UserInfoE.Token = value.Token;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion



    }

}
